<?php

// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath; // 不加这行语句的话会报错，提示找不到对应路径
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------

$storageBoxs = $db->getListOfStorageBoxs();

if (count($storageBoxs) > 0) {
    foreach ($storageBoxs as $storageBox) {
        $id = $storageBox["id"];
        $title = $storageBox["title"];
        $sortNumber = $storageBox["sortNumber"];
        echo <<<BBB
            <div class="mt-2 card shadow-sm">
                <div class="card-body">

                    <p class="card-text">$title</p>
                    <div class="d-flex justify-content-between align-items-center">

                        <div class="btn-group" role="group">
                            <a href="view.php?id={$id}" class="btn btn-outline-secondary">查看</a>
                            <a href="edit.php?id={$id}" class="btn btn-outline-secondary">编辑</a>
                            <button type="button"
                                    data-id="{$id}"
                                    class="btn btn-outline-secondary btnDelete">删除</button>
                        </div>

                        <div class="btn-group" role="group">
                            <!-- 注意自定义属性是不区分大小写的 -->
                            <button type="button" 
                                    data-id="{$id}"
                                    data-sortnumber="{$sortNumber}"
                                    class="btn btn-outline-secondary btnUp">↑</button>
                            <button type="button" 
                                    data-id="{$id}"
                                    data-sortnumber="{$sortNumber}"
                                    class="btn btn-outline-secondary btnDown">↓</button>
                        </div>

                    </div>

                </div>

            </div>
        BBB;
    }
}

// -----------------------------------------------------------------------------
